import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:huajianshe_app/base/AppNavigator.dart';
import 'package:huajianshe_app/base/BaseState.dart';
import 'package:huajianshe_app/common/AppRouter.dart';
import 'package:huajianshe_app/common/C.dart';
import 'package:huajianshe_app/common/TS.dart';
import 'package:huajianshe_app/common/load_image.dart';
import 'package:huajianshe_app/common/space.dart';
import 'package:huajianshe_app/network/Api.dart';
import 'package:huajianshe_app/pages/circle/model/CircleModel.dart';
import 'package:huajianshe_app/utils/toast_utils.dart';
import 'package:huajianshe_app/widget/SmartButton.dart';

class PrePostPage extends StatefulWidget {



  @override
  State<StatefulWidget> createState() {
    return PrePostPageState();
  }
}

class PrePostPageState extends BaseState<PrePostPage> {

  List<SimpleCircleInfo>? joined;
  List<SimpleCircleInfo>? created;

  @override
  void initState() {
    super.initState();
    getCircles(false);
  }

  void post(BuildContext context, int postType) {
    if (joined?.isNotEmpty == true || created?.isNotEmpty == true) {
      AppNavigator.pop(context);
      AppNavigator.push(context, RouteName.POST, arguments: {'type': postType, 'joined': joined, 'created': created});

    } else {
      getCircles(true);
      Toast.show('请先加入或创建一个圈子');
    }
  }

  void getCircles([bool doNotShowProgress = true]) {
    sendReq(Api.joinedAndCreatedCircles(), MyCirclesResp(), data: {});
  }

  @override
  void onReqSuccess<T>(T t, int code, String msg, String path) {
    if (t is MyCirclesResp) {
      this.joined = t.data?.joined;
      this.created = t.data?.created;
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: Colors.transparent, //Color.fromRGBO(0xff, 0xff, 0xff, 0.75),
        body:
        ClipRect(child: BackdropFilter(filter: ImageFilter.blur(sigmaX: 20.0, sigmaY: 20.0),
            child:
            Container(
              width: double.infinity,
              height: double.infinity,
              color: Color.fromRGBO(0xff, 0xff, 0xff, 0.75),
              child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
                H(80.0),
                Padding(padding: EdgeInsets.only(left: 36),
                    child: Text('发布你此刻的心情\n商机/工作思考/行业观察', style: TS(24, Color(0xff4e4e51), fontWeight: FontWeight.bold))
                ),
                Spacer(),
                Padding(padding: EdgeInsets.symmetric(horizontal: 50),
                    child: Row(mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [
                      SmartButton(text: '发布动态', textColor: C.gray666, fontSize: 12, backgroundColor: Colors.transparent, borderColor: Colors.transparent,
                          width: 100, height: 120, drawableTop: LoadImage('post_moment', width: 80, height: 80,), drawablePadding: 2, onPressed: () { post(context, PostType.MOMENT); }),
                      SmartButton(text: '发布商机', textColor: C.gray666, fontSize: 12, backgroundColor: Colors.transparent, borderColor: Colors.transparent,
                          width: 100, height: 120, drawableTop: LoadImage('post_opportunity', width: 80, height: 80), drawablePadding: 2, onPressed: () { post(context, PostType.OPPORTUNITY); }),
                    ])
                ),
                H(18),
                Container(width: double.infinity,
                    child: SmartButton(backgroundColor: Colors.transparent, borderColor: Colors.transparent,
                        height: 48, width: 48, drawableLeft: LoadImage('close_prepost'), onPressed: () { AppNavigator.pop(context); })
                ),
                H(15)
              ]),
            )
        ))
    );
  }
}

class PostType {
  static const int MOMENT = 1;
  static const int OPPORTUNITY = 2;
}